AllowableIdentifiers

class AllowableIdentifiers @JvmOverloads constructor(predicate: Predicate<Identifier>, supplier: Supplier<List<Identifier>>, cache: Boolean = false) : EntryValidator<Identifier> , EntrySuggester<Identifier>

Defines a set of allowable identifiers for use in validation. Also supplies Suggestions to generate suggestion popups in-game.

NOTE: Expectation is that the predicate and supplier are based on matching sets of information; someone in theory could use the suppliers information to predicate an input, and the predicate could be used on a theoretical "parent" dataset of identifiers to derive the same contents as the supplier. Behavior may be undefined if this isn't the case.

Author

fzzyhmstrs

Since

0.2.0, added cache flag 0.5.0

Parameters

predicate

Predicate - tests a candidate Identifier to see if it is allowable

supplier

Supplier> - supplies all allowable identifiers in the form of a list. As typical with suppliers, it is not required but beneficial that the supplier provide a new list on each call

cache

Boolean that determines if get calls are cached. This can improve performance on high volume calls where the data doesn't change in the background (like Registries, once populated).

See also

Constructors

Link copied to clipboard
constructor(predicate: Predicate<Identifier>, supplier: Supplier<List<Identifier>>, cache: Boolean = false)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun get(): List<Identifier>

Supplies the allowable identifier list. As of 0.5.0, can be set to pull a memoized (cached) value.

Link copied to clipboard
open override fun getSuggestions(input: String, cursor: Int, choiceValidator: ChoiceValidator<Identifier>): CompletableFuture<Suggestions>

Returns Suggestions based on the allowable identifier list and a choice validator

Link copied to clipboard
fun test(identifier: Identifier): Boolean

Test the provided Identifier vs. the predicate

Link copied to clipboard
open override fun validateEntry(input: Identifier, type: EntryValidator.ValidationType): ValidationResult<Identifier>

Validates the provided Identifier versus the provided Predicate